//
//  ByCellProductDetailTags.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/2.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellProductDetailServices.h"

@implementation ByCellProductDetailServices

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setModel:(ByModelProductDetail *)model {
    
    _model = model;
    
    [self setServices];
}
- (void)setServices {
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *lastView;
    for (int i = 0; i < _model.services.count; i ++) {
        
        UIView *basalView = [UIView new];
        [self.contentView addSubview:basalView];
        
        UIImageView *iconView = [UIImageView new];
        iconView.image = [UIImage imageWithColor:BY_BLUE_COLOR];
        [basalView addSubview:iconView];
        
        UILabel *serviceLabel = [[UILabel alloc] init];
        serviceLabel.adjustsFontSizeToFitWidth = true;
        serviceLabel.text = _model.services[i];
        serviceLabel.font = FONT(14);
        serviceLabel.textAlignment = NSTextAlignmentRight;
        serviceLabel.textColor = [UIColor lightGrayColor];
        [basalView addSubview:serviceLabel];
        
        
        [basalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(@0);
            make.width.equalTo(self.contentView).multipliedBy(1.0 / 4);
            if (i == 0) {
                make.left.equalTo(@0);
            } else {
                make.left.equalTo(lastView.mas_right);
            }
        }];
        [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(15, 15));
            make.left.equalTo(@10);
            make.centerY.equalTo(@0);
        }];
        [serviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(@0);
            make.right.equalTo(@-10);
            make.left.equalTo(iconView.mas_right).offset(5);
        }];
        
        lastView = basalView;
    }
}

@end
